home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 351-375 / 351 / pdc / pdcsrc.lzh / PDC / List.c < prev    next >
C/C++ Source or Header  |  1990-04-06  |  6KB  |  244 lines

  1.  
  2. /* PDC Compiler - A Freely Distributable C Compiler for the Amiga
  3.  *                Based upon prior work by Matthew Brandt and Jeff Lydiatt.
  4.  *
  5.  * PDC Compiler release 3.3 Copyright (C) 1989 Paul Petersen and Lionel Hummel.
  6.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  7.  *
  8.  * This code is freely redistributable upon the conditions that this 
  9.  * notice remains intact and that modified versions of this file not be 
  10.  * distributed as part of the PDC Software Distribution without the express
  11.  * consent of the copyright holders.
  12.  *
  13.  *------------------------------------------------------------------
  14.  *
  15.  * $Log:    List.c,v $
  16.  * Revision 3.33  90/04/05  22:36:00  lionel
  17.  * Prepending of library function's '.' moved from call_library().
  18.  * 
  19.  * Revision 3.32  90/02/03  16:24:51  lionel
  20.  * None
  21.  * 
  22.  *------------------------------------------------------------------
  23.  */
  24.  
  25. /*
  26.  * List.c
  27.  * 
  28.  * Generates a verbose listing of PDC's results from parsing the source.
  29.  */
  30.  
  31. #include    <stdio.h>
  32. #include    "C.h"
  33. #include    "Expr.h"
  34. #include    "Gen.h"
  35. #include    "Cglbdec.h"
  36.  
  37. #ifdef PROTO
  38. void put_sc(enum e_sc);
  39. void put_ty(TYP);
  40. void list_var(SYM, int);
  41. void list_table(TABLE, int);
  42. #else
  43. void put_sc();
  44. void put_ty();
  45. void list_var();
  46. void list_table();
  47. #endif
  48.  
  49. extern char    *itoa();
  50.  
  51. void
  52. put_sc(scl)
  53.     enum e_sc       scl;
  54. {
  55.     char *storage_class = NULL;
  56.  
  57.     switch (scl) {
  58.     case sc_static:
  59.         storage_class = "Static      ";
  60.         break;
  61.     case sc_auto:
  62.         storage_class = "Auto        ";
  63.         break;
  64.     case sc_global:
  65.         storage_class = "Global      ";
  66.         break;
  67.     case sc_external:
  68.         storage_class = "External    ";
  69.         break;
  70.     case sc_type:
  71.         storage_class = "Type        ";
  72.         break;
  73.     case sc_const:
  74.         storage_class = "Constant    ";
  75.         break;
  76.     case sc_member:
  77.         storage_class = "Member      ";
  78.         break;
  79.     case sc_proto:
  80.         storage_class = "Prototype   ";
  81.         break;
  82.     case sc_parameter:
  83.         storage_class = "Parameter   ";
  84.         break;
  85.     case sc_label:
  86.         storage_class = "Label";
  87.         break;
  88.     case sc_ulabel:
  89.         storage_class = "Undefined label";
  90.         break;
  91.     }
  92.  
  93.     if (storage_class) {
  94.         fprintf( list, storage_class );
  95.     }
  96. }
  97.  
  98. void
  99. put_ty(tp)
  100.     TYP            *tp;
  101. {
  102.     char *type = NULL;
  103.  
  104.     if (tp == NULL)
  105.         return;
  106.  
  107.     switch (tp->type) {
  108.     case bt_char:
  109.         type = "Char";
  110.         break;
  111.     case bt_uchar:
  112.         type = "unsigned Char";
  113.         break;
  114.     case bt_short:
  115.         type = "Short";
  116.         break;
  117.     case bt_ushort:
  118.         type = "unsigned Short";
  119.         break;
  120.     case bt_enum:
  121.         type = "enum ";
  122.         goto ucont;
  123.     case bt_long:
  124.         type = "Long";
  125.         break;
  126.     case bt_unsigned:
  127.         type = "unsigned long";
  128.         break;
  129.     case bt_float:
  130.         type = "Float";
  131.         break;
  132.     case bt_double:
  133.         type = "Double";
  134.         break;
  135.     case bt_pointer:
  136.         fprintf( list, ( tp->val_flag ? "Array of " : "Pointer to " ));
  137.         put_ty(tp->btp);
  138.         break;
  139.     case bt_union:
  140.         type = "union ";
  141.         goto ucont;
  142.     case bt_struct:
  143.         type = "struct ";
  144. ucont:      if (tp->sname == NULL)
  145.             type = "<no name> ";
  146.         else {
  147.             fprintf( list, "%s ", tp->sname );
  148.             type = NULL;
  149.         }
  150.         break;
  151.     case bt_typedef:
  152.         type = "typedef ";
  153.         goto ucont;
  154.     case bt_ifunc:
  155.     case bt_func:
  156.         fprintf( list, "Function returning " );
  157.         type = NULL;
  158.         put_ty(tp->btp);
  159.         break;
  160.     }
  161.  
  162.    if (type) {
  163.         fprintf( list, type );
  164.    }
  165. }
  166.  
  167. void
  168. list_var(sp, i)
  169.     SYM            *sp;
  170.     int             i;
  171. {
  172.     int             j;
  173.     char           *disp;
  174.  
  175.     if (Options.List) {
  176.         for (j = i; j; --j)
  177.             fprintf( list, "    " );
  178.  
  179.         disp = sp->name;
  180.         if (disp == NULL)
  181.             disp = "(empty)";
  182.  
  183.         fprintf( list, "%10s = %-8d ", disp, strlen(disp) );
  184.         put_sc(sp->storage_class);
  185.         put_ty(sp->tp);
  186.         fprintf( list, "\n" );
  187.     }
  188.  
  189.     if (sp->storage_class == sc_external) {
  190.         if (strncmp("__BUILTIN_", sp->name, 10) != 0) {
  191.             if (strncmp("__LIBCALL_", sp->name, 10) != 0) {
  192.                 if (sp->value.i != 0) { /* Don't do xref if not used */
  193.                     if (sp->storage_type == sc_library)
  194.                         fprintf( output, "\tXREF\t%s\n", sp->name );
  195.                     else
  196.                         fprintf( output, "\tXREF\t_%s\n", sp->name );
  197.                 }
  198.             }
  199.         }
  200.     }
  201.  
  202.     else if (sp->storage_class == sc_global) {
  203.         if (sp->tp == NULL || sp->tp->type != bt_typedef) {
  204.             if (strncmp("__BUILTIN_", sp->name, 10) != 0) {
  205.                 if (strncmp("__LIBCALL_", sp->name, 10) != 0) {
  206.                     fprintf( output, "\tXDEF\t_%s\n", sp->name );
  207.                 }
  208.             }
  209.         }
  210.     }
  211.  
  212.     if (sp->tp == NULL)
  213.         return;
  214.  
  215.     if ((sp->tp->type == bt_struct || sp->tp->type == bt_union) &&
  216.         sp->storage_class == sc_type)
  217.         list_table(&(sp->tp->lst), i + 1);
  218. }
  219.  
  220. void
  221. list_table(t, i)
  222.     TABLE          *t;
  223.     int             i;
  224. {
  225.     SYM            *sp;
  226.  
  227.     sp = t->head;
  228.  
  229.     /* If there are no symbols in the table, then note the fact in the listing
  230.      * file.  If there are symbols, then send each of them to list_var() along
  231.      * with the indent level variable, i, that was passed to us.
  232.      */
  233.  
  234.     if (sp == NULL) {
  235.         if (Options.List) {
  236.             fprintf( list, "(none)\n" );
  237.         }
  238.     }
  239.     else do {             /* sp != NULL on entry to loop */
  240.         list_var(sp, i);
  241.         sp = sp->next;
  242.     } while (sp != NULL);
  243. }
  244.